﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoBackupDatabase.DBConection;
using System.Data;
using System.Data.SqlClient;
using AutoBackupDatabase.ENT;

namespace AutoBackupDatabase.DAL
{
   public class ITEMDAL
    {
       private DbConnection conn;
       public ITEMDAL()
       {
           conn = new DbConnection();
       }

       public List<ITEMENT> GET_ITEM_ALL()
       {
           string query = string.Format("exec GET_ITEM_ALL ");
           DataTable ds = conn.executeGetQuery(query);
           List<ITEMENT> List = new List<ITEMENT>();
           foreach (DataRow item in ds.Rows)
           {
               ITEMENT ITEMent = new ITEMENT();
               ITEMent.ITEMID = int.Parse(item["ITEMID"].ToString());
               ITEMent.ITEMNAME = item["ITEMNAME"].ToString();
               ITEMent.PRICE =float.Parse( item["PRICE"].ToString());
               if (item["ISDRINK"].ToString().ToLower()=="true")
               {
                   ITEMent.ISDRINKGET=true;
               }
               else
                   ITEMent.ISDRINKGET = false;


               ITEMent.ITEMTYPEID = int.Parse(item["ITEMTYPEID"].ToString());
               ITEMent.ITEMTYPENAME = item["ITEMTYPENAME"].ToString();
               ITEMent.SHORTCUT = item["SHORTCUT"].ToString();
               List.Add(ITEMent);
           }

           return List;
       }
       public bool INSERTITEM(ITEMENT ent)
       {
           string query = "exec  INSERTITEM @ITEMNAME,@ITEMTYPEID,@ISDRINK,@PRICE,@SHORTCUT";
           SqlParameter[] sqlParameters = new SqlParameter[5];
           sqlParameters[0] = new SqlParameter("@ITEMNAME", SqlDbType.NVarChar);
           sqlParameters[0].Value = ent.ITEMNAME;
           sqlParameters[1] = new SqlParameter("@ITEMTYPEID", SqlDbType.Int);
           sqlParameters[1].Value = ent.ITEMTYPEID;
           sqlParameters[2] = new SqlParameter("@ISDRINK", SqlDbType.Int);
           sqlParameters[2].Value = ent.ISDRINK;
           sqlParameters[3] = new SqlParameter("@PRICE", SqlDbType.NVarChar);
           sqlParameters[3].Value = ent.PRICE;
           sqlParameters[4] = new SqlParameter("@SHORTCUT", SqlDbType.NVarChar);
           sqlParameters[4].Value = ent.SHORTCUT;
           return conn.executeInsertQuery(query, sqlParameters);
       }
       public bool UPDATEITEMBYITEMID(ITEMENT ent)
       {
           string query = "exec  UPDATEITEMBYITEMID @ITEMID,@ITEMNAME,@ITEMTYPEID,@ISDRINK,@PRICE,@SHORTCUT";
           SqlParameter[] sqlParameters = new SqlParameter[6];
           sqlParameters[4] = new SqlParameter("@ITEMID", SqlDbType.VarChar);
           sqlParameters[4].Value = ent.ITEMID;
           sqlParameters[0] = new SqlParameter("@ITEMNAME", SqlDbType.NVarChar);
           sqlParameters[0].Value = ent.ITEMNAME;
           sqlParameters[1] = new SqlParameter("@ITEMTYPEID", SqlDbType.Int);
           sqlParameters[1].Value = ent.ITEMTYPEID;
           sqlParameters[2] = new SqlParameter("@ISDRINK", SqlDbType.Int);
           sqlParameters[2].Value = ent.ISDRINK;
           sqlParameters[3] = new SqlParameter("@PRICE", SqlDbType.NVarChar);
           sqlParameters[3].Value = ent.PRICE;
           sqlParameters[5] = new SqlParameter("@SHORTCUT", SqlDbType.NVarChar);
           sqlParameters[5].Value = ent.SHORTCUT;
           return conn.executeUpdateQuery(query, sqlParameters);
       }
       public bool DELTELEITEMBYITEMID(ITEMENT ent)
       {
           string query = "exec  DELTELEITEMBYITEMID @ITEMID";
           SqlParameter[] sqlParameters = new SqlParameter[1];
           sqlParameters[0] = new SqlParameter("@ITEMID", SqlDbType.Int);
           sqlParameters[0].Value = ent.ITEMID;
           return conn.executeDeleteQuery(query, sqlParameters);
       }
    }
}
